﻿@model OnlineBookstore.Models.BookDetailsInfo
@{
    Layout = null;
}

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>购买 @Model.BookName - 广软智慧书城</title>
    <link rel="stylesheet" href="~/conjs/global.css" />
    <link href="~/conjs/cityLayout.css" type="text/css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <style>
        :root {
            --primary-color: #6c5ce7;
            --primary-dark: #5649c0;
            --text-color: #333;
            --border-color: #ddd;
            --light-bg: #f8f9fa;
            --radius: 6px;
            --shadow: 0 2px 10px rgba(0,0,0,0.1);
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Noto Sans SC', sans-serif;
            color: var(--text-color);
            background-color: #f5f7fa;
            line-height: 1.6;
        }

        /* 布局容器 */
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 15px;
        }

        /* 页眉样式 */
        .header {
            background-color: white;
            box-shadow: var(--shadow);
            padding: 15px 0;
        }

        .header-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .logo {
            font-size: 1.5rem;
            font-weight: 700;
            color: var(--primary-color);
            text-decoration: none;
        }

        /* 主要内容区 */
        .main-content {
            padding: 30px 0;
        }

        .form-container {
            background: white;
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            padding: 30px;
            max-width: 800px;
            margin: 0 auto;
        }

        .page-title {
            font-size: 1.5rem;
            color: var(--primary-color);
            margin-bottom: 1.5rem;
            padding-bottom: 0.5rem;
            border-bottom: 2px solid var(--primary-color);
        }

        /* 表单样式 */
        .form-group {
            margin-bottom: 1.5rem;
        }

            .form-group p {
                font-weight: 500;
                margin-bottom: 0.5rem;
                color: #555;
            }

        .form-control {
            width: 100%;
            padding: 10px 15px;
            border: 1px solid var(--border-color);
            border-radius: var(--radius);
            font-size: 1rem;
            font-family: inherit;
            transition: all 0.3s ease;
        }

            .form-control:focus {
                border-color: var(--primary-color);
                outline: none;
                box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.2);
            }

            .form-control[readonly] {
                background-color: var(--light-bg);
                cursor: not-allowed;
            }

        /* 按钮样式 */
        .btn {
            display: inline-block;
            padding: 10px 20px;
            background-color: var(--primary-color);
            color: white;
            border: none;
            border-radius: var(--radius);
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
            text-decoration: none;
            text-align: center;
        }

            .btn:hover {
                background-color: var(--primary-dark);
                transform: translateY(-2px);
            }

        .btn-outline {
            background-color: transparent;
            color: var(--primary-color);
            border: 1px solid var(--primary-color);
        }

            .btn-outline:hover {
                background-color: rgba(108, 92, 231, 0.1);
            }

        .action-buttons {
            display: flex;
            gap: 15px;
            margin-top: 30px;
        }

        /* 页脚样式 */
        .footer {
            text-align: center;
            padding: 20px 0;
            margin-top: 40px;
            border-top: 1px solid var(--border-color);
            color: #666;
            font-size: 0.9rem;
        }

        /* 错误消息 */
        .error-message {
            color: #e74c3c;
            margin-top: 5px;
            font-size: 0.9rem;
        }
    </style>
</head>
<body>
    <!-- 页眉 -->
    <header class="header">
        <div class="container header-content">
            <a href="/" class="logo">
                <i class="fas fa-book"></i>广软智慧书城
            </a>
            <div id="loginmsg">
                <!-- 登录状态信息 -->
            </div>
        </div>
    </header>

    <!-- 主要内容区 -->
    <main class="main-content">
       
            <div class="alert alert-danger">
                @ViewBag.BuyError
            </div>
            <div class="container">
                <div class="form-container">
                    <h1 class="page-title">购买 @Model.BookName</h1>

                    <form method="post">
                        <div class="form-group">
                            <p><i class="fas fa-book"></i> 书籍名称</p>
                            <input type="text" name="OrderName" class="form-control boxName" readonly>
                        </div>

                        <div class="form-group">
                            <p><i class="fas fa-calculator"></i> 数量</p>
                            <input type="text" name="OrderAmount" class="form-control boxAuthor" value="1">
                        </div>

                        <div class="form-group">
                            <p><i class="fas fa-tag"></i> 价格</p>
                            <input type="text" name="OrderPrice" class="form-control boxprice" readonly>
                        </div>

                        <div class="form-group">
                            <p><i class="fas fa-user"></i> 你的账号</p>
                            <input type="password" name="Id" class="form-control boxID" readonly>
                        </div>

                        <div class="form-group">
                            <p><i class="fas fa-map-marker-alt"></i> 地址</p>
                            <input id="sel1" name="OrderRegio" type="text" class="form-control city_input" readonly>
                        </div>

                        <div class="form-group">
                            <p><i class="fas fa-home"></i> 详情地址</p>
                            <input type="text" name="OrderAddress" class="form-control">
                        </div>

                        <div class="form-group">
                            <p><i class="fas fa-comment"></i> 备注</p>
                            <input type="text" id="x" name="Remark" class="form-control">
                        </div>

                        @if (!string.IsNullOrEmpty(ViewBag.err as string))
                        {
                            <div class="error-message">
                                <i class="fas fa-exclamation-circle"></i> @ViewBag.err
                            </div>
                        }
                        @if (ViewBag.buyError != null)
                        {
                            <div class="error-message">
                                <i class="fas fa-exclamation-circle"></i> @ViewBag.buyError
                            </div>
                        }
                        <div class="action-buttons">
                            <button type="submit" class="btn boxqd" data-buy-error="@ViewBag.buyError">
                                <i class="fas fa-check"></i> 确定购买
                            </button>
                            <a href="@Url.Action("Index")" class="btn btn-outline">
                                <i class="fas fa-arrow-left"></i> 返回
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </main>

    <!-- 页脚 -->
    <footer class="footer">
        <div class="container">
            <p>广软智慧书城 — MVC 项目 © @DateTime.Now.Year</p>
        </div>
    </footer>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script src="~/conjs/cityselect.js"></script>
    <script>
        $(document).ready(function() {
            // 设置表单初始值
            $('.boxName').val("@Html.Raw(Model.BookName)");
            $('.boxprice').val("@Html.Raw(Model.BookPrice)");
            $('.boxID').val("@Session["Id"]");

            // 购买按钮点击事件
            $('.boxqd').click(function(e) {
                // 验证表单
                var address = $('input[name="OrderAddress"]').val();
                if (!address || address.trim() === '') {
                    e.preventDefault();
                    alert('请填写详细地址');
                    return false;
                }


                var buyError = '@ViewBag.buyError';
                if (buyError =="余额不足，支付失败") {
                    alert("支付失败: "); // 显示错误信息
                    e.preventDefault(); // 阻止表单提交
                    return false; // 阻止表单提交
                } else {
                    alert("购买成功，即将返回书城首页");
                    return true; }


                // 确认购买
                if (confirm('确认购买《@Html.Raw(Model.BookName)》吗？')) {
                    alert("购买成功，即将返回书城首页");
                    return true;
                } else {
                    return false;
                }




            });

            // 数量变化时计算总价
            $('.boxAuthor').on('input', function() {
                var quantity = parseInt($(this).val()) || 0;
                var price = parseFloat("@Model.BookPrice") || 0;
                var total = (quantity * price).toFixed(2);
                $('.boxprice').val(total);
            }).trigger('input');
        });
    </script>
</body>
</html>